from utils import *


def main(path):
    img = cv2.imread(path)
    imgL = img[0:480, 0:640, :]
    imgR = img[0:480, 640:1280, :]
    json_file = "config/config.json"
    camera_matrix1, dist_coeffs1, camera_matrix2, dist_coeffs2, R, T = read_camera_parameters(json_file)
    rectified_img1, rectified_img2, Q = BinocularImageRectify(imgL, imgR, camera_matrix1, dist_coeffs1,
                                                              camera_matrix2,
                                                              dist_coeffs2, R, T)

    dis, _ = getDepthImage(rectified_img1, rectified_img2, window_size=3, min_disp=0, num=8, blockSize=30,
                           uniqueness_ratio=10, speckle_range=32,
                           speckle_window_size=100, disp12_max_diff=1)

    b, f, cx, cy = getBinocularSystemParameter(Q)
    detect_objects(imgL, dis=dis / 16, focal_length=f, baseline=-b, model_path='config/models.onnx',
                   class_names_path='config/class_names.txt')


if __name__ == '__main__':
    main('img/2.PNG')
